using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TestEnemy : MonoBehaviour,Damageable
{
    public float health = 100f;
    public Image healthBar;

    private Queue<float> damageMessage=new Queue<float>();

    private float healthBarWidth;
    private float maxHealth;

    public float Damage(GameObject source,float value)
    {
        float ret = value;
        health -= value;
        if (health < 0)
        {
            ret = value + health;
        }
        return ret;
    }

    // Start is called before the first frame update
    void Start()
    {
        healthBarWidth= healthBar.rectTransform.rect.width;
        maxHealth = health;
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void FixedUpdate()
    {
        if (health <= 0)
        {
            Destroy(gameObject);
        }
        UpdateHealth();
    }

    private void UpdateHealth()
    {
        healthBar.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, health / maxHealth * healthBarWidth);
    }


}
